package edu.ccut.saturn.studio.wfg.wfgmodel;

import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

import edu.ccut.saturn.studio.Activator;
import edu.ccut.saturn.studio.Images;
import edu.ccut.saturn.studio.core.search.IObserver;
import edu.ccut.saturn.studio.core.search.SaturnFileSearcher.SearchResult;
import edu.ccut.saturn.studio.core.util.eclipse.Messages;
import edu.ccut.saturn.studio.core.util.xml.SaturnW3CUtil;
import edu.ccut.saturn.studio.export.createhtml.Parameters;
import edu.ccut.saturn.studio.wfg.dialog.informationdialog.SaturnInformationDialog;
import edu.ccut.saturn.studio.wfg.figure.SaturnFigure;
import edu.ccut.saturn.studio.wfg.model.Shape;

public class SaturnInformationNode extends Shape {

	private static final long serialVersionUID = 1L;

	private Image informationPictureSmall = createImage(Activator.SMALL_INFORMATION_ICON);
	
	public static final String NAMENODE_INFORMATION = Messages.getString("SaturnInformationNode.InformationName"); //$NON-NLS-1$

	private static int number = 1;
	
	private String key = "";
	
	private String version = "";
	
	private String author = "";

	public SaturnInformationNode() {
		super.setName(NAMENODE_INFORMATION + number++);
		super.setSize(new Dimension(50, 50));
	}

	public Image getIcon() {
		return Activator.getImage(Images.BIG_INFORMATION_ICON);
	}
	
	public Image getSmallIcon() {
		return informationPictureSmall;
	}
	
	public void setSmallIcon(Image informationPictureSmall) {
		this.informationPictureSmall = informationPictureSmall;
	}

	@Override
	public IFigure getFigure() {
		SaturnFigure saturnFigure = new SaturnFigure();
		saturnFigure.setIcon(Activator.getImage(Images.BIG_INFORMATION_ICON));
		saturnFigure.setName(super.getName());
		return saturnFigure;
	}

	@Override
	public Node doRefresh(Document document) {
		Node rootNode = document.getDocumentElement();
		Node infoNode = document.createElement(SaturnName.KEY_NODE_ELEMENT_INFORMATION);
		SaturnW3CUtil.createChildNode(infoNode,SaturnName.KEY_NODE_NAME_KEY ,this.key);
		SaturnW3CUtil.createChildNode(infoNode,SaturnName.KEY_NODE_ELEMENT_VERSION ,this.version);
		SaturnW3CUtil.createChildNode(infoNode,SaturnName.KEY_NODE_ELEMENT_AUTHOR ,this.author);
		rootNode.appendChild(infoNode);
		return infoNode;
	}

	public Dialog getDialog() {
		SaturnInformationDialog dialog = new SaturnInformationDialog(Display.getDefault().getShells()[0],this);
		return dialog;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}


	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	@Override
	protected Node createChildNode(Document document, SaturnAttribute attrib,String name) {
		return null;
	}

	@Override
	public Shape cloneShape(Shape shape) {
		SaturnInformationNode informationNode = (SaturnInformationNode)shape;
		SaturnInformationNode newInformationNode = new SaturnInformationNode();
		newInformationNode.setName(informationNode.getName());
		newInformationNode.setId(informationNode.getId());
		newInformationNode.setNextId(informationNode.getNextId());
		newInformationNode.setKey(informationNode.getKey());
		newInformationNode.setAuthor(informationNode.getAuthor());
		newInformationNode.setVersion(informationNode.getVersion());
		newInformationNode.setDescription(informationNode.getDescription());
		newInformationNode.setSmallIcon(informationNode.getSmallIcon());
		return newInformationNode;
		
		
	}	public List<SearchResult> keyMapInWorkspace(IObserver observer) {
		
		return null;
	}
	
	
	public List<SearchResult> keyMapInProject(IObserver observer) {

		return null;
	}

	@Override
	public Parameters createNodeHtml(String filePath) {
		return null;
	}
}